<template>
  <div class="container">
    <div class="top-box">
      <div class="left-box">
        <div class="color-box"></div>
        <p>新增物资</p>
      </div>
      <div class="right-box">
        <el-button type="info" icon="el-icon-back" class="btn_fanhui" @click="Return">返回</el-button>
      </div>
    </div>
    <div class="content-box">
      <div class="table-box">
        <div class="item-box">
          <div class="number-box">用品分类</div>
          <div class="number1-box">
            <template>
              <el-select v-model="fidVal" placeholder="请选择" style="width:60%;" @change="Fl">
                <el-option
                  v-for="item in oneList"
                  :key="item.id"
                  :label="item.typeName"
                  :value="item.id"
                ></el-option>
              </el-select>
            </template>
          </div>
        </div>
        <div class="item-box">
          <div class="number-box">用品类别</div>
          <div class="number1-box">
            <template>
              <el-select v-model="typeName" placeholder="请选择" style="width:60%;" @change="Lb">
                <el-option
                  v-for="item in twoList"
                  :key="item.id"
                  :label="item.typeName"
                  :value="item.id"
                ></el-option>
              </el-select>
            </template>
          </div>
        </div>
        <div class="item-box">
          <div class="number-box">用品名称</div>
          <div class="number1-box">
            <el-input v-model="item.goodsName" style="width:60%;" placeholder="请输入用品名称"></el-input>
          </div>
        </div>
        <div class="item-box">
          <div class="number-box">用品单位</div>
          <div class="number1-box">
            <el-input v-model="item.goodsUnit" style="width:60%;" placeholder="请输入用品单位"></el-input>
          </div>
        </div>
        <div class="item-box">
          <div class="number-box">入库数量</div>
          <div class="number1-box">
            <el-input v-model="item.num" style="width:60%;" placeholder="请输入数量"></el-input>
          </div>
        </div>
        <div class="item-box" style="border-bottom:none;">
          <div class="number3-box">存放地址</div>
          <div class="number1-box">
            <el-input v-model="item.adress" style="width:60%;" placeholder="请输入存放地址"></el-input>
          </div>
        </div>
      </div>
      <div class="btn-box">
        <el-button type="primary" @click="addlist()">确定</el-button>
        <el-button type="info" @click="Return">返回</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data () {
    return {
      item: { fid: "", goodsName: "", num: "", adress: "", goodsUnit: "", creater: 0 },
      oneList: [],//物资一级分类
      fidVal: "",
      fid: 0,//一级分类
      twoList: [],//物资二级分类
      creater: 0,
      Mark: 0,
      typeName: "",
    };
  },
  created () {
    this.getoneList();
    this.creater = JSON.parse(localStorage.getItem("message")).Id;
  },
  methods: {
    Return () {
      window.history.go(-1);
    },
    //物资一级分类
    getoneList () {
      var obj = { creater: this.creater };
      var objs = JSON.stringify(obj);
      let the = { index: 15, jsondata: objs }
      axios.post("/apis/MyCenter.asmx/GetData", the).then(({ data }) => {
        var list = JSON.parse(data.d);
        this.oneList = list;
      });
    },
    //物资分类id
    Fl (e) {
      this.fid = e;
      //物资二级分类
      if (this.fid != 0) {
        var obj = { fid: this.fid };
        var objs = JSON.stringify(obj);
        let the = { index: 16, jsondata: objs }
        axios.post("/apis/MyCenter.asmx/GetData", the).then(({ data }) => {
          var list = JSON.parse(data.d);
          this.twoList = list;
        });
      }
    },
    //物资二级分类id
    Lb (e) {
      this.item.fid = e;
    },
    addlist () {
      if (this.Mark == 0) {
        //item: { fid: "", typeName: "", goodsName: "", num: "", address: "", goodsUnit: "", creater: 0 },
        if (this.item.fid == "" || this.item.fid == 0) { this.$message.error("请选择分类"); return; }
        if (this.item.typeName == "") { this.$message.error("请选择类别"); return; }
        if (this.item.goodsName == "") { this.$message.error("用品名称非空"); return; }
        if (this.item.goodsUnit == "") { this.$message.error("用品单位非空"); return; }
        if (this.item.adress == "") { this.$message.error("存放地址非空"); return; }
        this.item.creater = this.creater;
        var objs = JSON.stringify(this.item); let the = { index: 2, jsondata: objs };
        console.log()
        this.Mark = 1;
        axios.post("/apis/AdministrationManage.asmx/Add", the).then(({ data }) => {
          var list = JSON.parse(data.d);
          if (list.flag == true) {
            this.$message.success(list.tip);
            setTimeout(() => {
              window.history.go(-1);
            }, 500);
          } else {
            this.$message.error(list.tip);this.Mark = 0;
          }
        });
      }
    }
  }
};
</script>
<style lang="scss" scoped>
@import '@/assets/scss/base.scss';
.top-box {
  width: 100%;
  height: 60px;
  overflow: hidden;
  // border: 1px solid $red;
}
.left-box {
  width: 100px;
  height: 40px;
  float: left;
  margin-top: 10px;
  overflow: hidden;
  margin-left: 1%;
  // border: 1px solid red;
}
.color-box {
  width: 5px;
  height: 20px;
  float: left;
  margin-top: 10px;
  background-color: $Header_color;
}
.left-box p {
  float: left;
  margin-left: 5px;
  line-height: 40px;
}
.right-box {
  float: right;
  width: 90px;
  height: 40px;
  margin-right: 2%;
  border-radius: 8px;
  margin-top: 10px;
  background-color: $return-color;
  // border: 1px solid red;
}
.right-box:hover {
  background-color: #a4a6ad;
}
.right-box span {
  float: left;
  color: $white;
  font-size: $font-size-medium;
  line-height: 40px;
  //  border: 1px solid red;
}
.right-box img {
  width: 30px;
  height: 30px;
  margin-top: 5px;
  margin-left: 6px;
  float: left;
  // border: 1px solid red;
}
.content-box {
  width: 98%;
  height: 600px;
  margin: 0 auto;
  border-radius: 2px;
  background-color: $white;
  text-align: center;
  padding-top: 100px;
}
.table-box {
  width: 50%;
  margin: 0 auto;
  border: 1px solid $bordercolor;
}
.item-box {
  width: 100%;
  height: 60px;
  display: flex;
  border-bottom: 1px solid $bordercolor;
}
.number-box {
  width: 20%;
  height: 60px;
  line-height: 60px;
  text-align: center;
  color: $blackcolor;
  font-weight: bold;
  font-size: $font-size-medium;
  border-right: 1px solid $bordercolor;
}
.number3-box {
  width: 20%;
  height: 60px;
  line-height: 60px;
  text-align: center;
  color: $blackcolor;
  font-weight: bold;
  font-size: $font-size-medium;
  border-right: 1px solid $bordercolor;
}
.number1-box {
  flex: 1;
  // text-align: center;

  line-height: 55px;
}
.btn-box {
  width: 20%;
  height: 60px;
  margin: 0 auto;
  padding-left: 80px;
  margin-top: 40px;
  // border: 1px solid red;
}
</style>
